package wangm.netty.test1;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * description
 *
 * @author zk
 * @since 2018/7/20
 */
public class TimerInboundHandler extends ChannelInboundHandlerAdapter {
    public static Integer number = 0;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.channel().writeAndFlush(Unpooled.wrappedBuffer(("hello" + number++).getBytes()));

    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        String result = new String(ByteBufUtil.getBytes((ByteBuf) msg), "UTF-8");
        System.out.println(result);
        ctx.channel().writeAndFlush(Unpooled.wrappedBuffer(("hello" + number++).getBytes()));
    }

}
